package com.api.gbhg.heyulei.action;

import com.api.gbhg.heyulei.dao.DocumentAddDao;
import com.api.gbhg.heyulei.dao.impl.DocumentAddDaoImpl;
import com.api.gbhg.liuwenbo.action.AmountVerification;
import com.api.gbhg.liwenjun.VersionFlowUtil;
import weaver.conn.RecordSet;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.Properties;

/**
 * 报盘文件存入Action
 * @author hyl
 * @version 1.0
 * @date 2021/4/22 16:12
 */
public class DocumentAddAction implements Action {

    private DocumentAddDao documentAddDao = new DocumentAddDaoImpl();

    /**
     * 报盘文件数据添加
     * @param requestInfo
     * @return String
     */
    @Override
    public String execute(RequestInfo requestInfo) {
        try {
            //获取formId 例如：-83
            int mainTableId = VersionFlowUtil.getFlowTableLableId(requestInfo.getWorkflowid());
            //获取主表名
            String mainTabName = documentAddDao.getMainTableName(mainTableId);
            //获取表名
            String flowTableName = VersionFlowUtil.getFlowTableName(requestInfo.getWorkflowid());
            //获取流程当前id
            String id = AmountVerification.getIdByTable(flowTableName, requestInfo.getRequestid());
            //主表信息
            Map<String, Object> mainTableMap = documentAddDao.getMainTableMap(mainTabName);
            //获取明细表名称
            List<String> flowDetailTableNames = documentAddDao.getDetailTables(mainTableId);

            //明细表信息
            Map<String, Object> detailMap = documentAddDao.getDetailMap(flowDetailTableNames, id);

            mainTableMap.putAll(detailMap);
            // 当前登录人id
            mainTableMap.put("userId", requestInfo.getRequestManager().getUserId());

            //新增数据
            documentAddDao.addDocument(mainTableMap);
            return SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return FAILURE_AND_CONTINUE;
        }


    }


}
